/**
 * 
 */
package org.startup.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import org.startup.domain.Customer;
import org.startup.service.CustomerService;
import org.startup.utils.ServiceUtils;

import com.codahale.metrics.annotation.Timed;

/**
 * @author asudar
 * 
 */

@Path("/startup/customer")
@Produces(value = MediaType.APPLICATION_JSON)
public class CustomerResource {

	private CustomerService customerService = ServiceUtils.getCustomerService();

	@GET
	@Timed
	@Path("/getbyemail/{email}")
	public Response getBy(@PathParam("email") String email) {
		Customer customer = customerService.findBy(email);
		if (customer == null) {
			throw new RuntimeException("Customer Not Found with given E-Mail");
		}
		ResponseBuilder builder = Response.ok(customer);
		return builder.build();
	}

	@GET
	@Timed
	@Path("/getbyid/{id}")
	public Response getBy(@PathParam("id") Long id) {
		Customer customer = customerService.findBy(id);
		if (customer == null) {
			throw new RuntimeException("Customer Not Found with Given Id");
		}
		ResponseBuilder builder = Response.ok(customer);
		return builder.build();
	}

	@GET
	@Timed
	@Path("/getall")
	public Response getAll() {
		ResponseBuilder builder = Response.ok(customerService.getAll());
		return builder.build();
	}

}
